﻿using Glue.Internals;
using GlueTests.Builders;
using Xunit;

namespace GlueTests
{
    public class ArrayMemberTest
    {
        private readonly int[] integers;
        private readonly object returnValue;

        public class Person
        {
            public int[] Ints { get; set; }
        }

        public ArrayMemberTest()
        {
            var member = new PropertyBuilder(typeof(Person), "Ints").Build() as ICollectionMember;
            member.PassSpecialMappableCollections();
            integers = new [] {1,2};
            var person = new Person { Ints = integers };
            returnValue = member.InvokeGet(person);
        }

        [Fact]
        public void Should_send_IGlueCollection_from_getter()
        {
            
            Assert.True(returnValue is IGlueCollection);
        }

        [Fact]
        public void Should_return_right_values_in_IGlueCollection()
        {
            var collection = (IGlueCollection) returnValue;
            Assert.True(collection.MoveNext());
            Assert.Equal(integers[0],collection.Current);
            Assert.True(collection.MoveNext());
            Assert.Equal(integers[1], collection.Current);
        }

        [Fact]
        public void Should_return_correct_count()
        {
            var collection = (IGlueCollection)returnValue;
            Assert.Equal(2, collection.Count);
        }

        [Fact]
        public void MoveNext_should_return_false_when_no_more_elements()
        {
            var collection = (IGlueCollection)returnValue;
            Assert.True(collection.MoveNext());
            Assert.True(collection.MoveNext());
            Assert.False(collection.MoveNext());
        }

    }
}
